//
//  registViewController.swift
//  Community
//
//  Created by JKSD on 2019/8/6.
//  Copyright © 2019 ZKJ. All rights reserved.
//

import UIKit

class SEPTregistViewController: UIViewController {

    @IBOutlet weak var regist: UIButton!
    @IBOutlet weak var `protocol`: UIButton!
    @IBOutlet weak var login: UIButton!
    @IBOutlet weak var psdAgin: UITextField!
    @IBOutlet weak var psd: UITextField!
    @IBOutlet weak var count: UITextField!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "注册"
        self.regist.layer.cornerRadius = 25
        self.regist.clipsToBounds = true
        self.protocol.addTarget(self, action: #selector(toProtolo), for: UIControl.Event.touchUpInside)
    }
    
    @IBAction func signUp(_ sender: Any) {
        registCount()
    }
    
    func registCount() {
        if self.psd.text != self.psdAgin.text {
            LYProgressHUD.showMessage("两次密码不一样哦~")
            return
        }
        
        let stauts = CoreDataManager.shared.insertUser(userName: self.count.text!, password: self.psd.text!)
        switch stauts {
        case .success( _):
            self.navigationController?.popViewController(animated: true)
        case .failure(let message):
            LYProgressHUD.showMessage(message)
        }
 
    }
   @objc func toProtolo() {
        let web = WebViewController()
       web.requst(path: "index4")
    web.title = "用户协议"
        self.navigationController?.pushViewController(web, animated: true)
    }
    func getRandomString(_ number:Int! ,_ digital:Bool!,_ capital:Bool!,_ lowercase:Bool!) -> String{
        var number:Int! = number
        if number < 1 {
            number = 32
        }
        
        var strArray:Array<String> = Array()
        for _ in 0...INT64_MAX {
            let a:Int = Int(arc4random() % 122)
            let c:Character = Character(UnicodeScalar(a)!)
            //包含数字
            if digital {
                if a > 47 && a < 58{
                    strArray.append(String.init(c))
                }
            }
            //大写字母
            if capital {
                if a > 64 && a < 92 {
                    strArray.append(String.init(c))
                }
            }
            //小写字母
            if lowercase {
                if a > 96 && a < 123 {
                    strArray.append(String.init(c))
                }
            }
            if strArray.count == number{
                break
            }
        }
        let str:String = strArray.joined(separator: "")
        return str;
    }

}
